<template>
  <i v-if="props.name?.startsWith('el-')">
    <el-icon class="svg-icon" :color="props.color">
      <component :is="props.name.replace('el-', '')" />
    </el-icon>
  </i>
  <svg v-else class="svg-icon" aria-hidden="true" :fill="props.color">
    <use :xlink:href="iconName" />
  </svg>
</template>

<script setup lang="ts">
  import { computed } from 'vue'

  const props = defineProps({
    name: {
      type: String,
      required: true
    },
    width: {
      type: Number,
      default: 20
    },
    height: {
      type: Number,
      default: 20
    },
    color: {
      type: String,
      default: '#000'
    }
  })

  const iconName = computed(() => `#icon-${props.name}`)
</script>

<style scoped lang="less">
  .svg-icon {
    width: v-bind('props.width + "px"');
    height: v-bind('props.height + "px"');
    position: relative;
  }
</style>
